<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>state的简化写法</title>
    <script crossorigin src="https://unpkg.com/react@17/umd/react.development.js"></script>
    <script crossorigin src="https://unpkg.com/react-dom@17/umd/react-dom.development.js"></script>
    <script src="https://cdn.staticfile.org/babel-standalone/6.26.0/babel.min.js"></script>

</head>
<body>
    <div id="app">

    </div>
    <script type="text/babel">

        class Weather extends React.Component{

            state = {isHot:false,wind:'微风'}
            render(){
                const {isHot,wind} = this.state
                return  <h1 onClick={this.changeWeather}>今天天气很{isHot?'炎热':'凉爽'},{wind}</h1>
            }
            // 在类当中可以直接写赋值语句
            changeWeather= ()=>{// 如果写成function函数,this会直接是undefined
               // 箭头函数没有自己的this,它会往外部寻找
                console.log(this)
               const isHot = this.state.isHot
                this.setState({isHot: !isHot})
            }

        }
        ReactDOM.render(<Weather/>,document.getElementById('app'))
    </script>

</body>
</html>
